#ifndef SONGITEM_H
#define SONGITEM_H

#include <QGraphicsItem>
#include <QFont>
#include <QGraphicsProxyWidget>

#include "songinfo.h"

class InfoDownloader;
class LyricsText;

class SongItem : public QObject, public QGraphicsItem {
	Q_OBJECT;
	public:
		SongItem(QString artist, QString title);
		void useBaseColor(bool alternate);
		QRectF boundingRect() const { return rect; }
		void animateSizeTo(QSize newSize);
		void setupFadeTo(float o);
		void resize(QSize size);
		QSize getSize() const { return rect.size().toSize(); }
		void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
		qreal getYRotation() { return yRotation; }
		void setYRotation(qreal yrot);
	protected:
		QVariant itemChange(GraphicsItemChange change, const QVariant & value);
		void mousePressEvent(QGraphicsSceneMouseEvent* event);
		void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
		void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
	public slots:
		void onNextSongMoved(const QRectF geometry);
	private slots:
		void onSongInfoReady();
		void onCoverImageReady(QPixmap coverImage);
		void onLyricsReady(QString lyrics);
		void onFlipHalfway();
	signals:
		void geometryChanged(const QRectF);
	private:
		void toggleLyrics();
		void updateCover();
		SongInfo songInfo;
		QRectF rect;
		QColor fillColor;
		QFont textFont;
		InfoDownloader* infoDownloader;
		LyricsText* lyricsText;
		qreal yRotation;
		QPixmap shadowCover, renderedCover;
		Q_PROPERTY(QSize size READ getSize WRITE resize);
		Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity);
		Q_PROPERTY(qreal yrotation READ getYRotation WRITE setYRotation);
		QPixmap artistIcon, trackIcon, albumIcon;
};

#endif

